'''
文件的存取
'''
from pymongo import MongoClient
import bson.binary
client = MongoClient(host="mongodb://127.0.0.1",port=27017)
myset = client['good']['good']

# 存储
f = open('phtot1.png','rb')

#转换为mongodb的二进制数据存储形式
content = bson.binary.Binary(f.read())

#插入到数据库
myset.insert({"filenname":'phtot1,png','data':content})

#提取
data = myset.find_one({"filenname":'phtot1,png'})

#通过字典获取到数据库内容写入到本地
with open(data["filenname"],'wb') as f:
    f.write(data['data'])

client.close()
